package com.tiocloud.chat.feature.home.friend.adapter.viewholder;

import android.view.View;
import android.widget.TextView;

import com.tiocloud.chat.R;
import com.tiocloud.chat.feature.home.friend.adapter.BaseContactAdapter;
import com.tiocloud.chat.feature.home.friend.adapter.model.IContact;
import com.tiocloud.chat.feature.home.friend.adapter.model.item.ContactItem;
import com.tiocloud.chat.util.StringUtil;
import com.watayouxiang.androidutils.widget.imageview.TioImageView;

/**
 * author : TaoWang
 * date : 2020-01-16
 * desc : 联系人 ViewHolder
 */
public class ContactHolder extends BaseViewHolder<ContactItem> {

    @Override
    public int getLayoutId() {
        return R.layout.tio_contacts_item;
    }

    @Override
    public void convert(BaseContactAdapter adapter, int position, ContactItem item) {
        IContact contact = item.getContact();
        boolean lastPosition = item.isLastPosition();

        TextView name = findViewById(R.id.contacts_name);
        name.setText(StringUtil.nonNull(contact.getName()));

        TioImageView avatar = findViewById(R.id.contact_avatar);
        avatar.tio_roundAvatar(contact.getAvatar());

        View v_divider = findViewById(R.id.v_divider);
        v_divider.setVisibility(lastPosition ? View.INVISIBLE : View.VISIBLE);
    }
}
